<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 头部操作栏 -->
        <div class="layui-form lay-header">
          <div class="toolbar">
            <div class="layui-form-item lay-query-content">
              <div class="lay-query-box">
                <div class="query-lt">
                 
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">计件工资编号：</label>
                    <div class="layui-input-inline">
                      <input name="code" class="layui-input" type="text" placeholder="请输入计件工资编号" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">员工姓名：</label>
                    <div class="layui-input-inline">
                      <input name="theWorkOrderName" class="layui-input" type="text" placeholder="请输入报员工姓名" />
                    </div>
                  </div>
                  
                  
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">状态：</label>
                    <div class="layui-input-inline">
                      <select id="status" name="status">
                          <option value="">全部</option>
                          <option value="tosubmit">待提交</option>
                          <option value="confirm">待确认</option>
                          <option value="checked">已审核</option>
                          <option value="sendOver">已送审</option>
                          <option value="confirmed">已确认</option>
                          <option value="toSettle">待结算</option>
                          <option value="settled">已结算</option>
                      </select>
                    </div>
                  </div>
                  <!-- <div class="layui-inline">
                    <label class="layui-form-label w-auto">车间：</label>
                    <div class="layui-input-inline">
                      <select id="workshopId" name="workshopId"></select>
                    </div>
                  </div> -->
                  
                  <!-- 

                  -->
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">确认开始时间：</label>
                    <div class="layui-input-inline">
                      <input 
                        name="empConfirmTimeStart" 
                        id="empConfirmTimeStart" 
                        class="layui-input date-icon" 
                        type="text" 
                        placeholder="请选择时间" 
                        style="width: 200px" 
                        readonly 
                      />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">选择年月：</label>
                    <div class="layui-input-inline">
                      <input 
                        name="month" 
                        id="month" 
                        class="layui-input" 
                        type="text" 
                        placeholder="请选择年月" 
                        style="width: 200px" 
                        readonly 
                      />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">确认结束时间：</label>
                    <div class="layui-input-inline">
                      <input 
                        name="empConfirmTimeEnd" 
                        id="empConfirmTimeEnd" 
                        class="layui-input date-icon" 
                        type="text" 
                        placeholder="请选择时间" 
                        style="width: 200px" 
                        readonly 
                      />
                    </div>
                  </div>
                  
                  
                 

                </div>
                <div class="query-rt">
                  <div class="layui-inline">
                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="lay-btn-rows">
            <div class="lay-btn-box">
              <div class="lay-btn-lt">
                <!-- <button id="addProductionPlanBtn" class="layui-btn color-reseda" type="button">添加生产计划</button> -->
                <!-- <button id="addBtn" class="layui-btn color-reseda" type="button">批量审核</button> -->
                <!-- <button id="xxxxx" class="layui-btn color-reseda" type="button">xxxxx</button> -->
              </div>
              <div class="lay-btn-rt"></div>
            </div>
          </div>
        </div>
        <!-- 表格 -->
        <table class="layui-table" id="productionPlanTable" lay-filter="productionPlanTable"></table>
      </div>
    </div>
  </div>
  <style>
    div[lay-id="productionPlanTable"] .layui-table-cell {
      padding: 0 5px;
    }
  
    .table-auto .layui-table-cell {
      height: auto;
    }
  
    .template-box .w-auto {
      width: 110px !important;
      text-align: left;
      padding: 9px 0;
    }
  
    .template-box .addTable {
      height: 30px;
      line-height: 30px;
      padding: 0 10px;
    }
  
    .msg-none .layui-none {
      display: none !important;
    }
  
    .flex-item {
      display: flex;
      border-bottom: 1px solid #e6e6e6;
    }
  
    .left-btn {
      flex: 1;
      text-align: left;
    }
  
    .flex-between {
      width: calc(100% - 40px);
      display: flex;
      justify-content: space-between;
    }
  
    body .layui-table tbody tr.disabledBg {
      background-color: #f5f5f5 !important;
    }
  
    .layui-table-page-left {
      text-align: left;
    }
  
    .scroll-table-5-4 .layui-table-body {
      max-height: 535px;
    }
  
    .scroll-table-4-5 .layui-table-body {
      max-height: 490px;
    }
  
    /*   添加生产计划   */
    .addProductionPlanForm-title,
    .examineProductionPlanForm-title {
      width: 100%;
    }
  
    .addProductionPlanForm-title .title,
    .examineProductionPlanForm-title .title {
      display: inline-block;
      font-size: 16px;
      font-weight: bold;
      color: #333333;
      line-height: 19px;
      position: relative;
      padding: 6px 0 19px 0;
    }
  
    .addProductionPlanForm-title .title:after,
    .examineProductionPlanForm-title .title:after {
      content: "";
      display: block;
      position: absolute;
      left: 0;
      bottom: 0;
      width: calc(100% + 6px);
      height: 3px;
      background: #0a8b0a;
    }
  
    .line {
      width: 100%;
      height: 1px;
      background-color: #f8f8f8;
    }
  
    .addProductionPlanFormBox {
      padding: 20px 0;
    }
  
    .addProductionPlanFormBox .layui-col-md4 {
      margin: 5px 0;
    }
  
    .addProductionPlanFormBox .layui-form-label,
    addProductionPlanFormItem .layui-form-label {
      padding: 9px;
      width: 115px;
      font-size: 14px;
      font-weight: 400;
      color: #999999;
    }
  
    .addProductionPlanFormBox .layui-input-inline > input[readonly] {
      border-color: rgba(0, 0, 0, 0);
      outline: none;
    }
  
    .addProductionPlanFormBox .layui-input-inline > input[readonly]:focus,
    .addProductionPlanFormBox .layui-input-inline > input[readonly]:hover {
      border-color: transparent !important;
      outline: none;
    }
  
    form[lay-filter="examineProductionPlanForm"] textarea {
      width: 90%;
      resize: none;
      padding: 5px 10px;
      height: 100px;
      box-sizing: border-box;
    }
  
    form[lay-filter="examineProductionPlanForm"] .layui-table-cell {
      height: auto;
    }
  
    form[lay-filter="examineProductionPlanForm"] .layui-table-cell > img {
      height: 100%;
    }
  
    .addProductionPlanFormItem {
      padding: 15px 0 0 0;
    }
  
    .addProductionPlanFormItem .layui-input-block {
      margin-left: 133px;
      padding-right: 90px;
      box-sizing: border-box;
    }
  
    .open-details-box::-webkit-scrollbar {
      width: 0 !important;
    }
  </style>
  
  <!-- 表格操作列 -->
  <script type="text/html" id="productionPlanTableBar">
    <!-- {{# if(d.status=="cancellation"){ }} -->
    <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
    <!-- {{# }else{ }}  -->
    <!-- {{# if( d.status =="checkpending"){ }} -->
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <!-- {{# } }} -->
  
    <!-- 订单状态-->
    <!--checkpending(0,待审核);
      checked(1,已审核);
      rowproduce(2,待排产);
      alreadyrowproduce(3,已排产);
      tobeproduced(4,待生产);
      inproduction(5,生产中);
      accomplish(6,完成);-->
    <!--  当订单状态等于以上状态的时候不进行处理  等于其他状态的时候就显示确认提交按钮-->
    <!-- {{# if(d.whetherEdit=="0"&& d.status=="affirm"){ }} 
    {{# }else if(d.whetherEdit=="0"&& d.status=="checkpending"){ }} 
    {{# }else if(d.whetherEdit=="0"&& d.status=="checked"){ }} 
    {{# }else if(d.whetherEdit=="0"&& d.status=="rowproduce"){ }} 
    {{# }else if(d.whetherEdit=="0"&& d.status=="alreadyrowproduce"){ }} 
    {{# }else if(d.whetherEdit=="0"&& d.status=="tobeproduce"){ }} 
    {{# }else if(d.whetherEdit=="0"&& d.status=="inproduction"){ }} 
    {{# }else if(d.whetherEdit=="0"&& d.status=="accomplish"){ }} 
    
    {{# }else { }} -->
    <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
<!-- {{# if(d.status == "0"){ }} -->
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="confirmSubmission">确认</a>
   <!-- {{# } else if(d.status == "1"){ }} -->
   <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="audit">审核</a>
 <!-- {{# } else if(d.status == "2"){ }} -->
   <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="settle">结算</a>
 <!-- {{# } }} -->

    <!-- {{# } }} 
     
    {{# if(d.status=="affirm"||d.status=="checkpending"){ }} -->
    <!-- {{# } }} -->
  
    <!-- <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="toVoid">作废</a> -->
    <!-- {{# if(d.status=='checked' ||d.status=='alreadyrowproduce'){ }} -->
    <!-- {{# if(d.productionPlanHaveQuantity<d.productionQuantity){ }} -->
    <!-- {{# } }} -->
  
    <!-- {{# } }} -->
  
    <!-- {{# if(d.whetherProduction=="0" && d.checkStatus=='approve'){ }} -->
    <!-- {{# if(d.productionQuantity - d.productionPlanHaveQuantity == 0) { }} -->
    <!-- {{# } }} -->
    <!-- {{# } }}  -->
    <!-- {{# if(d.whetherProduction=="0" && d.status=='alreadyrowproduce'){ }} -->
    <!-- {{# } }}  -->
    <!-- {{# } }} -->
  </script>
  <!--关联物料表格操作列-->
  <script type="text/html" id="relevanceMaterialTableBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  </script>
  <!--台机排产表格操作列-->
  <script type="text/html" id="deviceProductionTableBar1">
    <!-- <a class="layui-btn layui-btn-xs" lay-event="detail">明细</a> -->
    <!-- {{# if(d.status=="no"){ }} -->
    <!-- <a class="layui-btn layui-btn-xs" lay-event="save">保存</a> -->
    <!-- {{# }else if(d.status =="yes"){ }} -->
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>
    <!-- {{# } }} -->
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  </script>
  <!--生产计划排产顶部表格-->
  <!--<script type="text/html" id="productionPlanModelTableBar">-->
  <!--    <button class="layui-btn layui-btn-danger" lay-filter="productionPlanFormSubmit" lay-submit>提交排产计划</button>-->
  <!--</script>-->
  
  <!-- 生产计划排产表单 -->
  <script type="text/html" id="productionPlanForm">
    <form lay-filter="productionPlanForm" class="layui-form open-form">
      <div class="open-model">
        <div class="open-auto">
          <div class="layui-form-item table-bor table-auto">
            <table class="layui-table" id="detailProductionPlanTable" lay-filter="detailProductionPlanTable"></table>
          </div>
          <div class="layui-tab" id="productionPlanBox" lay-filter="productionPlanBox" lay-allowclose="true">
            <div class="flex-item">
              <ul class="layui-tab-title br0" id="processNodsTitle"></ul>
              <!--                    <button id="addProcessNods" class="layui-btn" type="button" style="margin-left: 20px;">增加工序节点-->
              <!--                    </button>-->
            </div>
  
            <div class="layui-tab-content" id="processNodsContent"></div>
          </div>
        </div>
        <div class="layui-form-item text-right flex-between">
          <!-- <div class="left-btn">
            <div class="isData" style="display: none">
              <button id="saveProcessPlan" class="layui-btn" type="button">保存工序排产计划</button>
            </div>
          </div> -->
          <div class="right-btn">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productionPlanFormSubmit" lay-submit>提交</button>
          </div>
        </div>
      </div>
    </form>
  </script>
  <!--增加工序节点模板-->
  <script id="processNodsTitleTemplate" type="text/html">
    <!-- {{# layui.each(d, function(index, item){ }} -->
    <li lay-id="{{index}}">
      {{item.title }}
      <!--        <i class="layui-icon layui-icon-close layui-unselect layui-tab-close"></i>-->
    </li>
    <!-- {{# }) }} -->
  </script>
  <script id="processNodsContentTemplate" type="text/html">
    <!-- {{# layui.each(d, function(index, item){ }} -->
    <div class="layui-tab-item">
      <div class="" data-id="{{index}}">
        <div class="layui-row">
          <div class="layui-col-xs3" style="width: 33%; ">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">工序编码</label>
              <div class="layui-input-inline">
                <input name="productionQuantity" class="layui-input text-red br0" type="text" value="{{item.code}}" readonly="readonly" />
              </div>
            </div>
          </div>
          <!-- <div class="layui-col-xs3" style="width: 33%; ">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">已排产数量</label>
              <div class="layui-input-inline">
                <input name="productionQuantity" class="layui-input text-red br0" type="text" value="{{item.productionQuantity}}" readonly="readonly" />
              </div>
            </div>
          </div>
          <div class="layui-col-xs3" style="width: 33%;">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">平均合格率</label>
              <div class="layui-input-inline">
                <input name="yield" class="layui-input text-red br0" type="text" value="{{item.yield}}%" readonly="readonly" />
              </div>
            </div>
          </div> -->
          <div class="layui-col-xs3" style="width: 33%;">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">工资定额(元)</label>
              <div class="layui-input-inline">
                <input name="yield" class="layui-input text-red br0" type="text" value="{{item.salaryQuota}}" readonly="readonly" />
                <!-- <select name="pieceRateStatus{{index}}" lay-filter="pieceRateStatus{{index}}" lay-verify="required">
                  <option value="yes">启用计件工资</option>
                  <option value="no">不用计件工资</option>
                </select> -->
              </div>
            </div>
          </div>
          <!-- <div class="layui-col-xs3" id="isPieceRate{{index}}" style="width: 22%;">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">计件工资</label>
              <div class="layui-input-inline">
                <input name="pieceRate" class="layui-input pieceRate" type="text" value="{{item.pieceRate}}" lay-verify="required" />
              </div>
            </div>
          </div> -->
        </div>
        <div class="layui-row table-bor msg-none" style="margin-top: 15px;">
          <div class="layui-col-md7" style="padding-right: 25px">
            <div class="layui-form-item" style="margin-bottom: 10px;">
              <div class="open-details-title">机台排产</div>
            </div>
            <table class="layui-table" id="deviceProductionTable{{index}}" lay-filter="deviceProductionTable{{index}}"></table>
            <button class="layui-btn addTable addDeviceProduction" type="button">添加排产设备</button>
          </div>
          <div class="layui-col-md5">
            <div class="layui-form-item" style="margin-bottom: 10px;">
              <div class="open-details-title">关联物料</div>
            </div>
            <button class="layui-btn addTable addRelevanceMaterial" type="button">添加排产物料</button>
            <table class="layui-table" id="relevanceMaterialTable{{index}}" lay-filter="relevanceMaterialTable{{index}}"></table>
          </div>
        </div>
      </div>
    </div>
    <!-- {{# }) }} -->
  </script>
  <!--排产计划详情-->
  <script id="checkProductionPlanTemplate" type="text/html">
    <form lay-filter="checkProductionPlanForm" class="layui-form model-form form-scroll">
      <div class="open-details-box pd-20">
        <div class="layui-form-item table-bor table-auto">
          <table class="layui-table" id="checkProductionPlanTable" lay-filter="checkProductionPlanTable"></table>
        </div>
        <div class="layui-tab" id="checkProductionPlan" lay-filter="checkProductionPlan" style="display: none;">
          <div class="flex-item">
            <ul class="layui-tab-title br0" id="checkProcessNodsTitle"></ul>
          </div>
  
          <div class="layui-tab-content" id="checkProcessNodsContent" lay-filter="checkProcessNodsContent">
            <div class="template-box" data-id="{{index}}">
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">已排产数量</label>
                  <div class="layui-input-inline">
                    <input name="checkQuantity" class="layui-input text-red br0" type="text" value="" readonly="readonly" />
                  </div>
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">平均合格率</label>
                  <div class="layui-input-inline">
                    <input name="checkRate" class="layui-input text-red br0" type="text" value="" readonly="readonly" />
                  </div>
                </div>
              </div>
  
              <div class="layui-row table-bor msg-none" style="margin-top: 15px;">
                <div class="layui-col-md7">
                  <div class="layui-form-item" style="margin-bottom: 0;">
                    <div class="open-details-title">机台排产</div>
                  </div>
                  <table class="layui-table" id="checkDeviceProductionTable" lay-filter="checkDeviceProductionTable"></table>
                </div>
                <div class="layui-col-md5">
                  <div class="layui-form-item" style="margin-bottom: 0;">
                    <div class="open-details-title">关联物料</div>
                  </div>
                  <table class="layui-table" id="checkRelevanceMaterialTable" lay-filter="checkRelevanceMaterialTable"></table>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item text-right pd-20">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      </div>
    </form>
  </script>
  <script id="checkProcessNodsTitleTemplate" type="text/html">
    <!-- {{# layui.each(d, function(index, item){ }} -->
    <li lay-id="{{index}}" process-id="{{item.id}}">{{item.title}}</li>
    <!-- {{# }) }} -->
  </script>
  
  <!--选择工序-->
  <script type="text/html" id="selectProcessListAdd">
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-card-body">
          <!-- 头部操作栏 -->
          <div class="layui-form toolbar">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label w-auto">工序编号：</label>
                <div class="layui-input-inline mr0" style="width: 240px;">
                  <input name="code" class="layui-input" type="text" placeholder="工序编号" />
                </div>
              </div>
              <div class="layui-inline">
                <button class="layui-btn icon-btn" lay-filter="selectStorageSignListAddFormSubSearchLog" lay-submit style="padding: 0 24px;">搜索</button>
                <button id="selectStorageSignListAddClose" class="layui-btn icon-btn">确认选择</button>
              </div>
            </div>
          </div>
  
          <!-- 表格 -->
          <table class="layui-table" id="selectStorageSignListAddTable" lay-filter="selectStorageSignListAddTable"></table>
        </div>
      </div>
    </div>
  </script>
  <!--选择设备-->
  <script type="text/html" id="selectProcessDeviceByProcessId">
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-card-body">
          <!-- 头部操作栏 -->
          <div class="layui-form toolbar">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label w-auto">设备编码</label>
                <div class="layui-input-inline mr0" style="width: 240px;">
                  <input name="deviceCode" class="layui-input" type="text" placeholder="请输入设备编码" />
                </div>
              </div>
              <div class="layui-inline">
                <button class="layui-btn icon-btn" lay-filter="selectProcessFormSubSearchLog" lay-submit style="padding: 0 24px;">搜索</button>
                <button id="selectProcessDeviceByProcessIdClose" class="layui-btn icon-btn">确认选择</button>
              </div>
            </div>
          </div>
          <!-- 表格 -->
          <div class="scroll-table-4-5">
            <table class="layui-table" id="selectProcessDeviceByProcessIdTable" lay-filter="selectProcessDeviceByProcessIdTable"></table>
          </div>
        </div>
      </div>
    </div>
  </script>
 

  
  
  <!--表格操作按钮-->
  <script type="text/html" id="deviceWorkOrderTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
    <!-- {{# if(d.status=="toactivate"){ }} -->
    <a class="layui-btn layui-btn-xs" lay-event="activate">激活</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="close">关闭</a>
    <!-- {{# }else if(d.status =="inproduction"){ }} -->
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="pause">暂停</a>
    <!-- {{# }else if(d.status =="termination"){ }} -->
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="activate">激活</a>
    <!-- {{# } }} -->
    <a class="layui-btn layui-btn-xs" lay-event="up">上移</a>
    <a class="layui-btn layui-btn-xs" lay-event="down">下移</a>
  </script>
  
  <!--开工单详情-->
  <script id="getWorkOrderInfoTemplate" type="text/html">
    <form lay-filter="getWorkOrderInfoForm" class="layui-form model-form form-scroll">
      <div class="open-details-box pd-20">
        <div class="work-info" style="padding-top: 25px;">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label w-auto">工单编号：</label>
              <div class="layui-input-inline">
                <input name="workOrderCode" class="layui-input br0" type="text" readonly="readonly" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label w-auto">所属计划：</label>
              <div class="layui-input-inline">
                <input name="planCode" class="layui-input br0" type="text" readonly="readonly" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label w-auto">交货时间：</label>
              <div class="layui-input-inline">
                <input name="deliveryTime" class="layui-input br0" type="text" readonly="readonly" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label w-auto">订单录入人：</label>
              <div class="layui-input-inline">
                <input name="keyboarder" class="layui-input br0" type="text" readonly="readonly" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label w-auto">询价审核人：</label>
              <div class="layui-input-inline">
                <input name="enquiryAuditPerson" class="layui-input br0" type="text" readonly="readonly" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label w-auto">报价截止时间：</label>
              <div class="layui-input-inline">
                <input name="expirationDate" class="layui-input br0" type="text" readonly="readonly" />
              </div>
            </div>
          </div>
        </div>
        <div class="layui-form-item table-bor">
          <div class="layui-form-item" style="margin-bottom: 0;">
            <div class="open-details-title">工序排产明细</div>
          </div>
          <table class="layui-table" id="workInfoPlanDetailTable" lay-filter="workInfoPlanDetailTable"></table>
        </div>
        <div class="layui-form-item table-bor">
          <table class="layui-table" id="workInfoWorkOrderDetailTable" lay-filter="workInfoWorkOrderDetailTable"></table>
        </div>
        <div class="layui-form-item table-bor">
          <div class="layui-form-item" style="margin-bottom: 0;">
            <div class="open-details-title">工序关联物料明细</div>
          </div>
          <table class="layui-table" id="workInfoMaterialDetailTable" lay-filter="workInfoWorkOrderDetailTable"></table>
        </div>
      </div>
      <div class="layui-form-item text-right pd-20">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      </div>
    </form>
  </script>
  
  
  
 
  
  <!-- js部分 -->
  <script>
    layui.use(["layer", "form", "table", "admin", "laydate", "laytpl", "element", "upload"], async function () {
      var $ = layui.jquery;
      var layer = layui.layer;
      var form = layui.form;
      var table = layui.table;
      var config = layui.config;
      var admin = layui.admin;
      var laydate = layui.laydate;
      var laytpl = layui.laytpl;
      var element = layui.element;
      var upload = layui.upload;
      let processList = [];
      let where = {};
  
      let nowData = {};
      if (typeof parentData !== "undefined") {
        nowData = { ...parentData };
        if (nowData.eventName == "radio" || nowData.eventName == "checkbox") {
          $("#configFun").show();
        }
        if (nowData.where) {
          where = { ...nowData.where };
        }
        if (nowData.eventName == "planHis") {
          $("#addBtn").hide();
        }
      }
      // 年月选择器
        laydate.render({
          elem: '#month',
          type: 'month', // 关键配置：只选择年月
          format: 'yyyyMM', // 格式化值为 202506 形式
          done: function(value, date){
            // 如果需要进一步处理（如补零）
            if(value){
              var year = date.year;
              var month = (date.month < 10) ? '0' + date.month : date.month;
              var formatted = year + '' + month; // 拼接为 202506
              console.log('最终值:', formatted);
              // 如果需要绑定到隐藏字段
              $('input[name="month"]').val(formatted);
            }
          }
        });
      const deviceRes = await admin.initDataSelectPro("enterprise/device/admin/deviceWorkshop/list", {}, "workshopId", "车间", () => {}, "name");
       // 初始化日期选择器
       laydate.render({
          elem: '#empConfirmTimeStart',       // 绑定到输入框
          type: 'datetime',          // 选择日期和时间（可选：'date' 仅日期）
          format: 'yyyy-MM-dd HH:mm:ss', // 格式（根据需求调整）
          trigger: 'click',          // 点击触发
          done: function(value) {
            console.log('选择的时间：', value); // 选中的值会直接绑定到 input 的 value
          }
        });
          // 初始化日期选择器
          laydate.render({
          elem: '#empConfirmTimeEnd',       // 绑定到输入框
          type: 'datetime',          // 选择日期和时间（可选：'date' 仅日期）
          format: 'yyyy-MM-dd HH:mm:ss', // 格式（根据需求调整）
          trigger: 'click',          // 点击触发
          done: function(value) {
            console.log('选择的时间：', value); // 选中的值会直接绑定到 input 的 value
          }
        });
      laydate.render({
        elem: "#shipmentTime",
        type: "date",
        range: true,
        done: function (value, date, endDate) {
          if (value) {
            var dateValue = value.split(" - ");
            $("input[name='startShipmentTime']").val(dateValue[0] + " 00:00:00");
            $("input[name='endShipmentTime']").val(dateValue[1] + " 23:59:59");
          } else {
            $("input[name='startShipmentTime']").val("");
            $("input[name='endShipmentTime']").val("");
          }
        }
      });
      //生产计划状态
      // admin.getDictList(
      //   "status",
      //   "production_plan_status",
      //   null,
      //   "生产计划状态"
      // );
      let a = [];
  
      // 渲染表格
      var insTb = table.render({
        elem: "#productionPlanTable",
        url: config.base + "production/productionPlan/admin/productionPieceRate/list",
        page: true,
        cellMinWidth: 100,
        where: where,
        cols: [
                [
                {
                    type: "numbers", 
                    title: "序号"
                },
                {
                    field: "code", 
                    title: "计件工资核算记录编号", 
                    align: "center"
                },
                {
                    field: "creatorName", 
                    title: "员工姓名", 
                    align: "center"
                },
                {
                    field: "no", 
                    title: "员工工号", 
                    align: "center"
                },
                {
                    field: "month", 
                    title: "所属月份", 
                    align: "center"
                },
                {
                    field: "workQuantity", 
                    title: "报工单数", 
                    align: "center"
                },
                {
                    field: "qualifiedSalary", 
                    title: "合格工资", 
                    align: "center"
                },
                {
                    field: "unqualifiedSalary", 
                    title: "不合格工资", 
                    align: "center"
                },
                {
                    field: "scrapPenalty", 
                    title: "报废罚款", 
                    align: "center"
                },
                {
                    field: "pieceRateAmount", 
                    title: "计件金额", 
                    align: "center"
                },
                {
                    field: "status", 
                    title: "状态", 
                    align: "center",
                    templet: function(d) {
                        // 状态映射
                        const statusMap = {
                            0: "待确认",
                            1: "已确认",
                            2: "待结算",
                            3: "已结算"
                        };
                        return statusMap[d.status] || d.status;
                    }
                },
                {
                    field: "empConfirmTime", 
                    title: "员工确认时间", 
                    align: "center"
                },
                {
                    field: "financeConfirmTime", 
                    title: "财务确认时间", 
                    align: "center"
                },
                {
                    field: "settlementTime", 
                    title: "结算时间", 
                    align: "center"
},
                    {
                    align: "center",
                    toolbar: "#productionPlanTableBar",
                    title: "操作",
                    width: 150,
                    fixed: "right"
                    }
                ]
                ],
        done: function (res, curr, count) {
          a = table.cache["productionPlanTable"];
        }
      });
  
      // 工具条点击事件
      table.on("tool(productionPlanTable)", function (obj) {
        var data = obj.data;
        console.log(a);
        if (obj.event === "detail") {
          //修改
          showEditModel(data);
        } else if (obj.event === "plan") {
          //计划排产
          // productionPlanModel(data);
          admin.formOpen({
            area: ["85%", "90%"],
            title: "生产计划排产",
            path: "components/productionPlan/productionPieceRateForm.html",
            success: function () {
              parentData.eventName = "plan";
              // parentData.id = data.id;
              parentData.data = data;
            }
          });
        } else if (obj.event === "checkPlanRecord") {
          productionPlanRecordList(data);
        } else if (obj.event === "edit") {
          // 编辑生产计划
          // addProductionPlan(data, 'edit');
  
          openForm("edit", data.id);
        } else if (obj.event === "details") {
          // 生产计划详情
          // examineProductionPlanModel(data, "details");
          openForm("detail", data.id);
        } else if (obj.event === "confirmSubmission") {
  // 确认提交逻辑（已有）
  layer.open({
    title: "确认提交",
    content: "确认提交后，将无法修改",
    btn: ["确认", "取消"],
    yes: function () {
      admin.req(
        `production/productionPlan/admin/productionPieceRate/audit/${data.id}/confirm`,
        {},
        function (res) {
          if (res.code == 200) {
            layer.msg("确认提交成功", { icon: 1 });
            table.reload("productionPlanTable");
          } else {
            layer.msg(res.msg, { icon: 2 });
          }
        },
        "PUT"
      );
    }
  });
} else if (obj.event === "audit") {
  // 审核逻辑
  layer.open({
    title: "审核",
    content: "确定要审核该记录吗？",
    btn: ["确定", "取消"],
    yes: function () {
      admin.req(
        `production/productionPlan/admin/productionPieceRate/audit/${data.id}/audit`,
        {},
        function (res) {
          if (res.code == 200) {
            layer.msg("审核成功", { icon: 1 });
            table.reload("productionPlanTable");
          } else {
            layer.msg(res.msg, { icon: 2 });
          }
        },
        "PUT"
      );
    }
  });
} else if (obj.event === "settle") {
  // 结算逻辑
  layer.open({
    title: "结算",
    content: "确定要结算该记录吗？",
    btn: ["确定", "取消"],
    yes: function () {
      admin.req(
        `production/productionPlan/admin/productionPieceRate/audit/${data.id}/settle`,
        {},
        function (res) {
          if (res.code == 200) {
            layer.msg("结算成功", { icon: 1 });
            table.reload("productionPlanTable");
          } else {
            layer.msg(res.msg, { icon: 2 });
          }
        },
        "PUT"
      );
    }
  });
} else if (obj.event === "toVoid") {
          // 作废
          toVoidToolCabinet(data);
        }
      });
  
      //监听排序
      table.on("sort(productionPlanTable)", function (obj) {
        table.reload("productionPlanTable", {
          initSort: obj,
          where: {
            sort: obj.field,
            order: obj.type
          }
        });
      });
  
      // 搜索
      form.on("submit(formSubSearchLog)", function (data) {
        data.field.workshopName=''
        data.field.workshopName = deviceRes.find((v) => v.id == data.field.workshopId)?.name;
        insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
      });
  
      // 重置搜索
      form.on("submit(resets)", (data) => {
        data.field.workshopName=''
  
        insTb.reload({ where: admin.resetSearch(data.field), page: { curr: 1 } }, "data");
      });
  
      form.render("select");
  
      $("#addProductionPlanBtn").click(function () {
        addProductionPlan();
      });
      $("#addBtn").click(function () {
        openForm("add");
      });
      $("#xxxxx").click(function () {
        admin.formOpen({
          area: ["85%", "90%"],
          title: "生产计划排产",
          path: "components/component/checkSkuForm.html",
          success: function () {
            // parentData.url = "enterprise/product/admin/productDetailWMS/list";
            // parentData.where={
            //   skuName:'zhoudada-name'
            // }
            parentData.isPage = true;
          }
        });
      });
      function openForm(eventName, id) {
        admin.formOpen({
          type: 1,
          area: ["95%", "85%"],
          title: "详情",
          path: "components/productionPlan/productionPieceRateForm.html",
          success: function () {
            parentData.eventName = eventName;
            parentData.id = id;
          }
        });
      }
      // 显示编辑弹窗
      function productionPlanModel(data) {
        admin.open({
          type: 1,
          area: ["84%", "830px"],
          title: "物料生产计划排产",
          content: $("#productionPlanForm").html(),
          success: function () {
            let productionPlanId = data.id;
            let customerSkuCode = data.customerSkuCode;
            // 顶部详情数据
  
            var detailProductionPlanTable = table.render({
              elem: "#detailProductionPlanTable",
              data: [data],
              cellMinWidth: 100,
              cols: [
                [
                  {
                    field: "code",
                    align: "center",
                    title: "计划编号",
                    width: 150
                  },
                  // { field: "planSourceDesc", align: "center", title: "计划订单类型" },
                  { field: "bookCode", align: "center", title: "基准书编号" },
                  {
                    field: "customerSkuCode",
                    align: "center",
                    title: "生产物料"
                  },
                  {
                    field: "customerSkuSpec",
                    align: "center",
                    title: "物料规格"
                  },
                  {
                    field: "productTypeName",
                    align: "center",
                    title: "所属物料系列"
                  },
                  {
                    field: "productionQuantity",
                    align: "center",
                    title: "生产数量"
                  },
                  {
                    field: "productionPlanHaveQuantity",
                    title: "已排产数量",
                    align: "center"
                  },
                  {
                    field: "productionPlanQuantity",
                    title: "本次生产数量",
                    align: "center",
                    templet: admin.setTableInput("productionPlanQuantity")
                  },
                  // { field: "yeild", title: "合格率", align: "center" },
                  // { field: "customerName", align: "center", title: "客户信息" },
                  {
                    field: "shipmentTime",
                    align: "center",
                    title: "交货时间",
                    width: 160
                  },
                  { field: "statusDesc", align: "center", title: "状态" },
                  {
                    field: "createTime",
                    align: "center",
                    title: "创建时间",
                    width: 160
                  }
                ]
              ]
            });
            admin.tableInputChange("detailProductionPlanTable");
            // 节点数据
            let processNodsData = [];
            let nodeIndex = 0;
            // let processList = [];
            // 如果有缓存
            let saveProcessData = config.getTempData("saveProcessData");
            if (saveProcessData != undefined && saveProcessData != "") {
              // 如果有缓存则拿缓存的数据
              saveProcessData.forEach((item, index) => {
                if (item.productionPlanId == productionPlanId) {
                  item.title = "工序" + toChinesNum(processNodsData.length + 1);
                  processNodsData.push(item);
                }
              });
              if (processNodsData.length > 0) {
                addTemplate();
              }
            } else if (data.planNature == "process") {
              console.log("data1", data);
              // 如果计划有生产工序则隐藏添加按钮
              $("#addProcessNods").hide();
              $(".layui-tab-close").hide();
              getProcessOutputAndYield(data.processId, data.processName);
            } else {
              // 如果计划没有生产工序查当前基准书所有工序
              admin.req("enterprise/echnologyParam/admin/echnologyParam/getEchonlogyInfoBy/" + data.bookId, {}, async function (res) {
                if (res.code == 200) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    if (res.data.length > 0) {
                      for (const item of res.data) {
                        await getProcessOutputAndYield(item.id, item.name, item.salaryQuota, item);
                      }
                      //   res.data.forEach((item, index) => {
                      //     getProcessOutputAndYield(item.id, item.name, item.salaryQuota);
                      // });
                    } else {
                    }
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                }
              });
              // 节点标题
              // laytpl(processNodsTitleTemplate.innerHTML).render([], function (html) {
              //     $("#processNodsTitle").html(html);
              // });
              // 查询计划的排产工序
              // admin.req(
              //   'enterprise/echnologyParam/admin/echnologyParam/list',
              //   {
              //     skuCode: customerSkuCode,
              //   },
              //   function (res) {
              //     layer.closeAll('loading');
              //     if (res.code == 200) {
              //       if (res.data.length > 0) {
              //         res.data.forEach((item, index) => {
              //           getProcessOutputAndYield(item.id, item.name);
              //         });
              //       } else {
              //       }
              //     } else {
              //       layer.msg(res.msg, { icon: 2 });
              //     }
              //   },
              //   'GET',
              // );
            }
  
            // tab切换改变下标
            element.on("tab(productionPlanBox)", function () {
              nodeIndex = this.getAttribute("lay-id");
              console.log(processNodsData[nodeIndex]);
              table.reload("relevanceMaterialTable" + nodeIndex, {
                data: processNodsData[nodeIndex].skuList
              });
              // 是否计件工资
              initSelectPieceRate();
            });
  
            // 查询工序已排产数量和平均合格率
            async function getProcessOutputAndYield(processId, nodeNames, salaryQuota, obj) {
              // const res = await admin.reqPro("production/productionPlan/admin/productionPlan/getProcessOutputAndYield", {
              //   processId: processId,
              //   productionPlanId: productionPlanId
              // });
              console.log("dat1a", data);
  
              // admin.req(
              //   "production/productionPlan/admin/productionPlan/getProcessOutputAndYield",
              //   {
              //     processId: processId,
              //     productionPlanId: productionPlanId
              //   },
              //   async function (res) {
              layer.closeAll("loading");
              // if (res.code == 200) {
              let numIndex = "工序" + toChinesNum(processNodsData.length + 1);
              let planArr = {
                title: nodeNames, //标题
                productionPlanId: productionPlanId, //id
                processId: processId,
                skuCode: customerSkuCode,
                // productionQuantity: res.data.productionQuantity, //已排产数量
                // yield: res.data.yield, //合格率
                pieceRateStatus: "no", //是否计件工资
                pieceRate: "", //工资
                processDeviceList: [],
                materialList: [],
                salaryQuota: salaryQuota //工资定额
              };
              console.log(1111, data);
  
              if (data.planNature == "process") {
                const res1 = await admin.reqPro("enterprise/echnologyParam/admin/echnologyParam/getEchonlogyBy/" + processId);
                processNodsData.push({ ...res1.data, ...planArr });
                console.log(43232, { ...res1.data });
              } else {
                processNodsData.push({ ...planArr, ...obj });
              }
              console.log("processNodsData", processNodsData);
  
              // nodeIndex = processNodsData.length - 1;
              nodeIndex = 0;
              addTemplate();
              // } else {
              //   layer.msg(res.msg, { icon: 2 });
              // }
              //   },
              //   "GET"
              // );
            }
  
            // 添加模板
            function addTemplate() {
              $(".isData").show();
              // 加载节点标题
              templateTitle();
              // 加载节点内容
              templateContent();
            }
  
            // 节点标题
            function templateTitle() {
              laytpl(processNodsTitleTemplate.innerHTML).render(processNodsData, function (html) {
                console.log(processNodsData);
  
                $("#processNodsTitle").html(html);
                // 删除tab选项卡
                deleteTemplateTitle();
              });
            }
  
            // 删除当前节点内容
            function deleteTemplateTitle() {
              $(".layui-tab-close").click(function () {
                let that = $(this);
                layer.confirm(
                  "确定要删除当前工序吗？",
                  {
                    offset: "65px",
                    skin: "layui-layer-admin"
                  },
                  function (i) {
                    layer.close(i);
                    // 删除当前DOM
                    that.parents("#processNodsTitle").find("li").eq(nodeIndex).remove();
                    $("#processNodsContent").find(".layui-tab-item").eq(nodeIndex).remove();
                    // 如果有缓存则删除缓存
                    let filterList = [processNodsData[nodeIndex]];
                    let saveProcessData = config.getTempData("saveProcessData");
                    if (saveProcessData != undefined && saveProcessData != "") {
                      filterList.forEach((item) => {
                        let index = saveProcessData.findIndex((ele) => ele.processId == item.processId && ele.productionPlanId == item.productionPlanId);
                        if (index > -1) {
                          saveProcessData.splice(index, 1);
                        }
                      });
                    }
                    // 删除当前页面数据
                    processNodsData.splice(nodeIndex, 1);
                    // 如果当前数据长度为0则隐藏保存工序排产计划
                    if (processNodsData.length == 0) {
                      $(".isData").hide();
                    } else {
                      // processNodsData.forEach((item, index) => {
                      //     item.title = '工序' + toChinesNum(index + 1)
                      // });
                      // 删除tab选项卡则显示前面个tab 同时改变nodeIndex
                      nodeIndex--;
                      // 回调重新执行函数 重新渲染模板
                      addTemplate();
                    }
                    // 重新缓存数据
                    config.putTempData("saveProcessData", saveProcessData);
                  }
                );
              });
            }
  
            function initSelectPieceRate() {
              form.on("select(pieceRateStatus" + nodeIndex + ")", function (d) {
                let elem = d.elem;
                let elemVal = elem[elem.selectedIndex].value;
                let dom = "pieceRateStatus" + nodeIndex;
                // 如果下拉框是当前选项则回显值并改变数组 再判断是否显示计件工资
                console.log(1111);
                if (elem.name === dom) {
                  processNodsData[nodeIndex].pieceRateStatus = elemVal;
                  let selectDom = "#isPieceRate" + nodeIndex;
                  if (elemVal === "yes") {
                    $(selectDom).show();
                    $(selectDom).find("input").attr("lay-verify", "required");
                  } else {
                    $(selectDom).find("input").attr("lay-verify", "none");
                    $(selectDom).hide();
                  }
                }
              });
              // 排产设备工具条点击事件
              table.on("tool(deviceProductionTable" + nodeIndex + ")", function (obj) {
                console.log(111);
                let rowData = obj.data;
                let list = processNodsData[nodeIndex].processDeviceList;
                if (obj.event === "save") {
                  // 保存
                  let planProductionQuantity = $(this).parents("td").siblings().find(".planProductionQuantity").val();
                  // if (planProductionQuantity == "") {
                  //   layer.msg("请输入计划排产数量", { icon: 2 });
                  //   return false;
                  // }
                  list.forEach((item, index) => {
                    if (rowData.deviceCode === item.deviceCode) {
                      list[index].status = "yes";
                      list[index].planProductionQuantity = planProductionQuantity;
                    }
                  });
                } else if (obj.event === "del") {
                  //删除
                  list.forEach((item, index) => {
                    if (rowData.deviceCode === item.deviceCode) {
                      list.splice(index, 1);
                    }
                  });
                } else if (obj.event === "edit") {
                  //修改
                  list.forEach((item, index) => {
                    if (rowData.deviceCode === item.deviceCode) {
                      list[index].status = "no";
                    }
                  });
                } else if (obj.event === "detail") {
                  // 明细
                  getDeviceWorkOrderPageList(rowData);
                }
                // 渲染表格
                table.reload("deviceProductionTable" + nodeIndex, {
                  data: list
                });
                console.log(processNodsData, "排产设备数据");
              });
  
              // 排产物料操作系列
              table.on("tool(relevanceMaterialTable" + nodeIndex + ")", function (obj) {
                let rowData = obj.data;
                // let list = processNodsData[nodeIndex].skuList;
                let list = table.cache["relevanceMaterialTable" + nodeIndex];
                console.log(list, "list");
  
                if (obj.event === "del") {
                  //删除
                  // list.forEach((item, index) => {
                  //   if (rowData.productDetailId === item.productDetailId) {
                  //     list.splice(index, 1);
                  //   }
                  // });
                  let index = $(obj.tr[0]).data("index");
                  list.splice(index, 1);
                  // table.reload("skuTable", { data: list });
                }
                // 渲染表格
                table.reload("relevanceMaterialTable" + nodeIndex, {
                  data: list
                });
              });
  
              // 计件工资
              $("body").delegate(".pieceRate", "change", function () {
                let reg = /^[1-9]+[0-9]*$/;
                let val = $(this).val();
                let list = processNodsData[nodeIndex];
                if (!reg.test(val)) {
                  layer.msg("请输入正确的数字", { icon: 2 });
                  $(this).val("");
                } else {
                  list.pieceRate = val;
                }
              });
  
              // 计划排产数量
              $("body").delegate(".planProductionQuantity", "change", function () {
                let id = $(this).attr("deviceId");
                let reg = /^[1-9]+[0-9]*$/;
                let planProductionQuantity = $(this).val();
                let list = processNodsData[nodeIndex].processDeviceList;
                list.forEach((item) => {
                  if (item.id === id) {
                    if (!reg.test(planProductionQuantity)) {
                      layer.msg("请输入正确的数字", { icon: 2 });
                      $(this).val("");
                    }
                  }
                });
              });
            }
  
            // 节点内容
            function templateContent() {
              laytpl(processNodsContentTemplate.innerHTML).render(processNodsData, function (html) {
                $("#processNodsContent").html(html);
                // 显示最新的添加项
                $("#processNodsTitle").find("li").removeClass("layui-this").eq(nodeIndex).addClass("layui-this");
                $("#processNodsContent").find(".layui-tab-item").removeClass("layui-show").eq(nodeIndex).addClass("layui-show");
                form.render("select");
                // 选择工序带出默认物料
                let isMaterialList = processNodsData[nodeIndex].materialList;
                if (isMaterialList.length == 0) {
                  let processId = processNodsData[nodeIndex].processId;
                  admin.reqSync(
                    "production/productionPlan/admin/productionPlan/getProcessMaterialPageList",
                    {
                      processId: processId,
                      skuCode: customerSkuCode
                    },
                    function (res) {
                      if (res.code == 200) {
                        let list = [];
                        res.data.forEach((ele) => {
                          list.push({
                            materialSkuCode: ele.skuCode,
                            processId: processId
                          });
                        });
                        processNodsData[nodeIndex].materialList = list;
                      } else {
                        layer.msg(res.msg, { icon: 2 });
                      }
                    },
                    "GET"
                  );
                }
                for (let i = 0; i < processNodsData.length; i++) {
                  // 关联物料表格
                  table.render({
                    elem: "#relevanceMaterialTable" + i,
                    data: processNodsData[i].materialList,
                    cellMinWidth: 100,
                    page: false,
                    cols: [
                      [
                        { type: "numbers", width: 40, title: "序号" },
                        // { field: "materialSkuCode", title: "物料信息", align: "center", width: 250 },
                        {
                          field: "skuCode",
                          title: "物料编码",
                          align: "center"
                        },
                        {
                          field: "skuName",
                          title: "物料名称",
                          align: "center"
                        },
                        {
                          field: "quantity",
                          title: "需求数量",
                          align: "center",
                          edit: "textarea"
                        },
  
                        {
                          align: "center",
                          toolbar: "#relevanceMaterialTableBar",
                          title: "操作",
                          width: 80
                        }
                      ]
                    ]
                  });
                  table.on("edit(relevanceMaterialTable" + i + ")", function (obj) {
                    var value = obj.value; // 得到修改后的值
                    var data = obj.data; // 得到所在行所有键值
                    var field = obj.field; // 得到字段
                    var index = $(obj.tr).data("index");
  
                    // 更新数据中对应的字段
                    var update = {};
                    update[field] = value;
                    obj.update(update);
                    processNodsData[i].skuList[index][field] = value;
                    // 编辑后续操作，如提交更新请求，以完成真实的数据更新
                    // …
  
                    // 显示当前行最新数据 - 仅用于示例展示
                    // showData(data);
                  });
                  // 机台排产表格
                  table.render({
                    elem: "#deviceProductionTable" + i,
                    data: processNodsData[i].processDeviceList,
                    cellMinWidth: 100,
                    page: false,
                    cols: [
                      [
                        { type: "numbers", width: 50, title: "序号" },
                        {
                          field: "deviceModel",
                          width: 150,
                          title: "设备型号",
                          align: "center"
                        },
                        {
                          field: "deviceCode",
                          width: 140,
                          title: "设备编码",
                          align: "center"
                        }
                        // { field: "yeild", width: 130, title: "机台平均合格率", align: "center" },
                        // {
                        //   field: "planProductionQuantity",
                        //   title: "计划排产数量",
                        //   align: "center",
                        //   width: 155,
                        //   templet: function (d) {
                        //     if (d.status == "yes") {
                        //       return "<span>" + d.planProductionQuantity + "</span>";
                        //     } else {
                        //       return (
                        //         '<input deviceId="' +
                        //         d.id +
                        //         '" class="layui-input planProductionQuantity" style="height: 28px;" type="text" ' +
                        //         'value="' +
                        //         d.planProductionQuantity +
                        //         '" />'
                        //       );
                        //     }
                        //   }
                        // },
                        // { field: "shipmentTime", title: "计划截止时间", align: "center", width: 160 },
                        // {
                        //   align: "center",
                        //   toolbar: "#deviceProductionTableBar",
                        //   title: "操作",
                        //   width: 240
                        // }
                      ]
                    ]
                  });
                  // 回显计件工资
                  let select = "dd[lay-value=" + processNodsData[i].pieceRateStatus + "]";
                  $(`select[name='pieceRateStatus${i}']`).siblings("div.layui-form-select").find("dl").find(select).click();
                  $("#isPieceRate" + i)
                    .find("input")
                    .attr("lay-verify", "none");
                  $("#isPieceRate" + i).hide();
                }
                // 是否计件工资
                initSelectPieceRate();
              });
  
              // 添加排产设备
              $(".addDeviceProduction").click(function () {
                let processId = processNodsData[nodeIndex].processId;
                let arrList = [];
                processNodsData[nodeIndex].processDeviceList.forEach((item) => {
                  arrList.push(item.deviceCode);
                });
                var selectProcessDeviceByProcessId = admin.open({
                  type: 1,
                  title: "排产设备",
                  area: "75%",
                  offset: ["100px", "380px"],
                  content: $("#selectProcessDeviceByProcessId").html(),
                  success: function () {
                    form.render("select");
                    // 渲染表格
                    var selectProcessDeviceByProcessIdTable = table.render({
                      elem: "#selectProcessDeviceByProcessIdTable",
                      url: config.base + "enterprise/device/admin/device/list",
                      page: true,
                      cellMinWidth: 100,
                      cols: [
                        [
                          { type: "checkbox" },
                          {
                            field: "deviceCode",
                            align: "center",
                            title: "设备编码"
                          },
                          { field: "name", align: "center", title: "设备名称" },
                          {
                            field: "deviceModelName",
                            align: "center",
                            title: "设备型号"
                          },
                          {
                            field: "createTime",
                            align: "center",
                            title: "创建时间"
                          }
                        ]
                      ],
                      done: function (res, curr, count) {
                        // 如果选择过的checkbox 则通过code标识判断 禁用下拉框
                        let allCheck = true;
                        for (let item in res.data) {
                          if (arrList.indexOf(res.data[item].deviceCode) !== -1) {
                            allCheck = false;
                          }
                          break;
                        }
                        if (!allCheck) {
                          $(".layui-table-header")
                            .find("input[name = 'layTableCheckbox'][lay-filter='layTableAllChoose']")
                            .each(function () {
                              $(this).attr("disabled", "disabled").next().removeClass("layui-form-checked");
                              form.render("checkbox");
                            });
                        }
                        let i = 0;
                        $(".layui-table-body.layui-table-main")
                          .find("input[name='layTableCheckbox']")
                          .each(function () {
                            if (arrList.indexOf(res.data[i].deviceCode) != -1) {
                              $(this).attr("disabled", "disabled").removeAttr("checked");
                              $(this).parents("tr").addClass("disabledBg");
                              form.render("checkbox");
                              // $(this).siblings(".layui-form-checkbox").css("opacity", "0");
                            }
                            i++;
                          });
                        i = 0;
                        $(".layui-table-fixed.layui-table-fixed-l")
                          .find(".layui-table-body")
                          .find("input[name='layTableCheckbox']")
                          .each(function () {
                            if (arrList.indexOf(res.data[i].deviceCode) != -1) {
                              $(this).attr("disabled", "disabled").removeAttr("checked");
                              $(this).parents("tr").addClass("disabledBg");
                              form.render("checkbox");
                              // $(this).siblings(".layui-form-checkbox").css("opacity", "0");
                            }
                            i++;
                          });
                      }
                    });
  
                    // 搜索
                    form.on("submit(selectProcessFormSubSearchLog)", function (data) {
                      selectProcessDeviceByProcessIdTable.reload(
                        {
                          where: data.field,
                          page: { curr: 1 }
                        },
                        "data"
                      );
                    });
  
                    // 确认选择
                    $("#selectProcessDeviceByProcessIdClose").click(function () {
                      let checkStatus = table.checkStatus("selectProcessDeviceByProcessIdTable"); //test即为基础参数id对应的值
                      let dataS = checkStatus.data;
                      if (checkStatus.data.length == 0) {
                        layer.msg("请选择设备", { icon: 2, time: 1000 });
                      } else {
                        let list = processNodsData[nodeIndex].processDeviceList;
                        // let filterList = list.filter((item) => {
                        //     return item.deviceCode == dataS[0].deviceCode
                        // });
                        // if (filterList.length > 0) {
                        //     layer.msg('当前选择的设备已存在', {icon: 2});
                        //     return false;
                        // }
                        dataS.forEach((item) => {
                          list.push({
                            processId: processId,
                            id: item.id,
                            deviceCode: item.deviceCode,
                            deviceModel: item.deviceModel,
                            planProductionQuantity: "", //计划排产数量
                            yeild: item.yeild, //台机评价合格率
                            shipmentTime: data.shipmentTime, //当前计划截止时间从data数据带出
                            status: "no"
                          });
                        });
                        layer.close(selectProcessDeviceByProcessId);
  
                        // 渲染表格
                        table.reload("deviceProductionTable" + nodeIndex, {
                          data: list
                        });
                        $(".open-details-box").scrollTop($(".open-details-box").height());
                      }
                    });
                  }
                });
              });
  
              // 添加关联物料
              $(".addRelevanceMaterial").click(function () {
                let index = $(".layui-tab-title .layui-this").attr("lay-id");
                let list = table.cache["relevanceMaterialTable" + index];
                console.log(list);
                console.log(processNodsData[index].skuList);
  
                admin.formOpen({
                  title: "配置关联物料",
                  area: "90%",
                  offset: "50px",
                  path: "components/purchase/skuTableForm.html",
                  success: function () {
                    parentData.notInListIds = list.map((v) => v.productDetailId).join(",");
                  },
                  end: function () {
                    console.log(index);
                    if (childData.list && childData.list.length > 0) {
                      list = [...list, ...childData.list];
                      processNodsData[index].skuList = list;
                      table.reload("relevanceMaterialTable" + index, {
                        data: list
                      });
                    }
                    // let checkStatus = table.checkStatus("selectProcessMaterialPageListTable"); //test即为基础参数id对应的值
                    // let dataS = checkStatus.data;
                    // if (checkStatus.data.length == 0) {
                    //   layer.msg("请选择物料", { icon: 2, time: 1000 });
                    // } else {
                    //   let list = processNodsData[nodeIndex].materialList;
                    //   let filterList = list.filter((item) => {
                    //     return item.materialSkuCode == dataS[0].skuCode;
                    //   });
                    //   if (filterList.length > 0) {
                    //     layer.msg("当前选择的物料已存在", { icon: 2 });
                    //     return false;
                    //   }
                    //  let len = $(this).parents('.template-box').data('id');
                    //   list.push({
                    //     materialSkuCode: dataS[0].skuCode,
                    //     processId: processId
                    //   });
                    //   // 渲染表格
                    //   table.reload("relevanceMaterialTable" + nodeIndex, {
                    //     data: list
                    //   });
                    //   layer.close(selectProcessMaterialPageList);
                    // }
                  }
                });
  
                //   let processId = processNodsData[nodeIndex].processId;
                //   var selectProcessMaterialPageList = admin.open({
                //     type: 1,
                //     title: "排产物料",
                //     area: "82%",
                //     offset: ["100px", "280px"],
                //     content: $("#selectProcessMaterialPageList").html(),
                //     success: function () {
                //       //物料类别
                //       admin.initDataSelectTree(true, "enterprise/product/admin/productType/getTreeData", null, "selectProductType", null, "物料类别", "productTypeId", null);
                //       form.render("select");
                //       // 渲染表格
                //       var selectProcessDeviceByProcessIdTable = table.render({
                //         elem: "#selectProcessMaterialPageListTable",
                //         url: config.base + "enterprise/product/admin/productDetail/list",
                //         page: true,
                //         cellMinWidth: 100,
                //         cols: [
                //           [
                //             { type: "radio" },
                //             { field: "skuCode", title: "物料编码", align: "center" },
                //             { field: "skuName", title: "物料名称", align: "center" },
                //             { field: "skuSpec", title: "物料规格", align: "center" },
                //             { field: "productTypeName", title: "物料类型", align: "center" },
                //             { field: "unitName", title: "物料单位", align: "center" },
                //             { field: "quantityStock", title: "库存数量", align: "center" },
                //             { field: "createTime", title: "创建时间", align: "center" }
                //           ]
                //         ]
                //       });
  
                //       // 获取物料类型
                //       admin.reqSync(
                //         "enterprise/product/admin/productType/getProductTypeVOAll",
                //         {},
                //         function (res) {
                //           if (res.code == 200) {
                //             $.each(res.data, function (index, item) {
                //               $("#productTypeId").append(new Option(item.name, item.id));
                //             });
                //           } else {
                //             layer.msg(res.msg, { icon: 2 });
                //           }
                //         },
                //         "GET"
                //       );
  
                //       // 获取物料分类
                //       admin.reqSync(
                //         "enterprise/product/admin/productCategory/getAll",
                //         {},
                //         function (res) {
                //           if (res.code == 200) {
                //             $.each(res.data, function (index, item) {
                //               $("#productCategoryId").append(new Option(item.name, item.id));
                //             });
                //           } else {
                //             layer.msg(res.msg, { icon: 2 });
                //           }
                //         },
                //         "GET"
                //       );
  
                //       form.render("select");
  
                //       // 搜索
                //       form.on("submit(selectProcessMaterialPageListFormSubSearchLog)", function (data) {
                //         selectProcessDeviceByProcessIdTable.reload(
                //           {
                //             where: data.field,
                //             page: { curr: 1 }
                //           },
                //           "data"
                //         );
                //       });
  
                //       // 确认选择
                //       $("#selectProcessMaterialPageListClose").click(function () {
                //         let checkStatus = table.checkStatus("selectProcessMaterialPageListTable"); //test即为基础参数id对应的值
                //         let dataS = checkStatus.data;
                //         if (checkStatus.data.length == 0) {
                //           layer.msg("请选择物料", { icon: 2, time: 1000 });
                //         } else {
                //           let list = processNodsData[nodeIndex].materialList;
                //           let filterList = list.filter((item) => {
                //             return item.materialSkuCode == dataS[0].skuCode;
                //           });
                //           if (filterList.length > 0) {
                //             layer.msg("当前选择的物料已存在", { icon: 2 });
                //             return false;
                //           }
                //           // let len = $(this).parents('.template-box').data('id');
                //           list.push({
                //             materialSkuCode: dataS[0].skuCode,
                //             processId: processId
                //           });
                //           // 渲染表格
                //           table.reload("relevanceMaterialTable" + nodeIndex, {
                //             data: list
                //           });
                //           layer.close(selectProcessMaterialPageList);
                //         }
                //       });
                //     }
                //   });
              });
            }
  
            // 缓存当前数据
            $("#saveProcessPlan").click(function () {
              let saveProcessData = config.getTempData("saveProcessData");
              let tempList = [],
                currentData = processNodsData[nodeIndex];
              let filterList = [currentData];
              if (currentData.processDeviceList.length == 0) {
                layer.msg("请添加排产设备", { icon: 2 });
                return false;
              }
              if (currentData.materialList.length == 0) {
                layer.msg("请添加排产物料", { icon: 2 });
                return false;
              }
              if (saveProcessData != undefined && saveProcessData != "") {
                // 筛选是否有相同ID的数据
                filterList.forEach((item) => {
                  let index = saveProcessData.findIndex((ele) => ele.processId == item.processId && ele.productionPlanId == item.productionPlanId);
                  if (index > -1) {
                    saveProcessData[index] = item;
                  } else {
                    saveProcessData.push(item);
                  }
                });
              } else {
                tempList.push(currentData);
                saveProcessData = tempList;
              }
              config.putTempData("saveProcessData", saveProcessData);
              layer.msg("缓存成功", { icon: 1 });
            });
  
            // 提交数据
            form.on("submit(productionPlanFormSubmit)", function (d) {
              let deviceFilter = [],
                flag = false;
              if (processNodsData.length == 0) {
                layer.msg("请添加工序", { icon: 2 });
                return false;
              }
              // 循环判断不能提交为空的数据
              console.log("processNodsData11", processNodsData);
  
              processNodsData.forEach((item, index) => {
                // console.log(table.cache["relevanceMaterialTable" + index]);
  
                // item.materialList = item.skuList;
                item.materialList = table.cache["relevanceMaterialTable" + index];
                item.skuList = table.cache["relevanceMaterialTable" + index];
                if (item.processDeviceList.length == 0) {
                  layer.msg(`${item.title}排产设备不能为空`, { icon: 2 });
                  flag = true;
                  return false;
                }
                if (item.materialList.length == 0) {
                  layer.msg(`${item.title}排产物料不能为空`, { icon: 2 });
                  flag = true;
                  return false;
                }
                deviceFilter = item.processDeviceList.filter((item) => {
                  return item.status == "yes";
                });
                // if (deviceFilter.length == 0) {
                //   layer.msg(`请保存${item.title}的排产设备`, { icon: 2 });
                //   flag = true;
                //   return false;
                // }
              });
              // 控制不能提交为空的数据
              if (flag) {
                return false;
              }
              let productionList = [];
              processNodsData.forEach((item) => {
                // 筛选出有保存过的排产设备
                // let deviceFilter = item.processDeviceList.filter((item) => {
                //   return item.status == "yes";
                // });
                let list = [];
                item.processDeviceList.forEach((ele) => {
                  list.push({
                    deviceCode: ele.deviceCode,
                    deviceModel: ele.deviceModel,
                    planProductionQuantity: ele.planProductionQuantity,
                    outputQuantity: ele.outputQuantity,
                    processId: ele.processId
                  });
                });
                // 提交的数组
                productionList.push({
                  productionPlanId: item.productionPlanId,
                  processId: item.processId,
                  processName: item.title,
                  pieceRateStatus: item.pieceRateStatus,
                  pieceRate: item.pieceRate,
                  skuCode: item.skuCode,
                  processDeviceList: list,
                  materialList: item.materialList,
                  skuList: item.skuList
                });
              });
              layer.load(2);
              let formData = {
                productionPlanId: table.cache["detailProductionPlanTable"][0].id,
                productionPlanQuantity: table.cache["detailProductionPlanTable"][0].productionPlanQuantity,
                productionPlanHaveQuantity: table.cache["detailProductionPlanTable"][0].productionPlanHaveQuantity,
                submitProductionPlanForms: productionList
              };
              console.log(formData);
              console.log(table.cache["detailProductionPlanTable"]);
  
              // return false;
              // 提交计划
              admin.req(
                "production/productionPlan/admin/productionPlan/submitProductionPlan",
                JSON.stringify(formData),
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    // 提交成功清空缓存数据
                    let saveProcessData = config.getTempData("saveProcessData");
                    let saveList = [];
                    if (saveProcessData != undefined && saveProcessData != "") {
                      saveProcessData.forEach((item) => {
                        if (item.productionPlanId != productionPlanId) {
                          saveList.push(item);
                        }
                      });
                    }
                    config.putTempData("saveProcessData", saveList);
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("productionPlanTable");
                    layer.closeAll();
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                "POST",
                true,
                "application/json; charset=utf-8"
              );
              return false;
            });
          }
        });
      }
  
      // 通过设备明细查询生产开工单列表
      function getDeviceWorkOrderPageList(data) {
        admin.open({
          type: 1,
          area: ["82%", "830px"],
          offset: "65px",
          title: "生产开工单列表",
          content: $("#deviceWorkOrderTemplate").html(),
          success: function () {
            form.render("select");
            var deviceWorkOrderTable = table.render({
              elem: "#deviceWorkOrderTable",
              url: config.base + "production/productionPlan/admin/productionPlan/getDeviceWorkOrderPageList?deviceCode=" + data.deviceCode,
              page: true,
              cellMinWidth: 100,
              cols: [
                [
                  { type: "numbers", title: "序号" },
                  { field: "code", title: "工单编码", align: "center" },
                  { field: "processName", title: "所属工序", align: "center" },
                  { field: "planCode", title: "所属生产计划", align: "center" },
                  {
                    field: "workOrderQualityDesc",
                    title: "工单性质",
                    align: "center"
                  },
                  { field: "skuName", title: "物料名称", align: "center" },
                  { field: "skuCode", title: "物料编码", align: "center" },
                  {
                    field: "productTypeName",
                    title: "所属系列",
                    align: "center"
                  },
                  {
                    field: "productionQuantity",
                    title: "计划数量",
                    align: "center"
                  },
                  {
                    field: "outputQuantity",
                    title: "排产数量",
                    align: "center"
                  },
                  {
                    field: "predictFinishTime",
                    title: "预计完工时间",
                    align: "center"
                  },
                  { field: "statusDesc", title: "状态", align: "center" },
                  { field: "no", title: "排序", align: "center" },
                  {
                    align: "center",
                    toolbar: "#deviceWorkOrderTableBar",
                    title: "操作",
                    width: 280
                  }
                ]
              ]
            });
  
            form.on("submit(deviceWorkOrderFormSubSearchLog)", function (data) {
              deviceWorkOrderTable.reload({ where: data.field, page: { curr: 1 } }, "data");
              //return false;
            });
            // 工具条点击事件
            table.on("tool(deviceWorkOrderTable)", function (obj) {
              var data = obj.data;
              if (obj.event === "activate") {
                //激活
                operationWorkOrder(data.id, 0, "确定要激活吗？");
              } else if (obj.event === "pause") {
                // 暂停
                operationWorkOrder(data.id, 1, "确定要暂停吗？");
              } else if (obj.event === "close") {
                // 关闭
                operationWorkOrder(data.id, 2, "确定要关闭吗？");
              } else if (obj.event === "up") {
                // 上移
                moveWorkOrder(data.id, 1);
              } else if (obj.event === "down") {
                // 下移
                moveWorkOrder(data.id, 2);
              } else if (obj.event === "detail") {
                getWorkOrderInfoDialog(data.id, data.processId, data.skuCode);
              }
            });
  
            // 工单激活、暂停、关闭
            function operationWorkOrder(id, type, tips) {
              layer.confirm(
                tips,
                {
                  offset: "65px",
                  skin: "layui-layer-admin"
                },
                function (i) {
                  layer.close(i);
                  layer.load(2);
                  admin.req(
                    "production/productionPlan/admin/productionPlan/operationWorkOrder",
                    {
                      id: id,
                      type: type
                    },
                    function (res) {
                      layer.closeAll("loading");
                      if (res.code == 200) {
                        layer.msg(res.msg, { icon: 1 });
                        table.reload("deviceWorkOrderTable");
                      } else {
                        layer.msg(res.msg, { icon: 2 });
                      }
                    },
                    "PUT"
                  );
                }
              );
            }
  
            // 上移下移
            function moveWorkOrder(id, type) {
              layer.load(2);
              admin.req(
                "production/productionPlan/admin/productionPlan/moveWorkOrder",
                {
                  id: id,
                  operaType: type
                },
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("deviceWorkOrderTable");
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                "PUT"
              );
            }
          }
        });
      }
  
      // 开工单详情
      function getWorkOrderInfoDialog(id, processId, skuCode) {
        admin.open({
          type: 1,
          area: ["78%", "810px"],
          offset: "65px",
          title: "设备排产工单信息",
          content: $("#getWorkOrderInfoTemplate").html(),
          success: function () {
            let workerInfoData = {};
            // 获取工单详情
            admin.req(
              "production/productionPlan/admin/productionPlan/getWorkOrderInfo",
              {
                id: id,
                processId: processId,
                skuCode: skuCode
              },
              function (res) {
                if (res.code == 200) {
                  workerInfoData = res.data;
                  form.val("getWorkOrderInfoForm", workerInfoData);
                  $("input[name='workOrderCode']").val(workerInfoData.planDetail[0].workOrderCode);
                  $("input[name='planCode']").val(workerInfoData.planDetail[0].code);
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "GET",
              false
            );
  
            // 计划明细
            var workInfoPlanDetailTable = table.render({
              elem: "#workInfoPlanDetailTable",
              data: workerInfoData.planDetail,
              cellMinWidth: 120,
              cols: [
                [
                  {
                    field: "productTypeName",
                    title: "物料类型",
                    align: "center"
                  },
                  {
                    field: "customerSkuCode",
                    title: "客户SKU料号",
                    align: "center"
                  },
                  {
                    field: "customerSkuName",
                    title: "客户SKU名称",
                    align: "center"
                  },
                  {
                    field: "customerSkuSpec",
                    title: "客户规格码",
                    align: "center"
                  },
                  { field: "unitName", title: "单位", align: "center" },
                  {
                    field: "demandQuantity",
                    title: "需求数量",
                    align: "center"
                  },
                  {
                    field: "outputQuantity",
                    title: "排产数量",
                    align: "center"
                  },
                  {
                    field: "workstationQuantity",
                    title: "排产工站数",
                    align: "center"
                  },
                  // { field: "customerName", title: "客户信息", align: "center" },
                  { field: "statusDesc", title: "状态", align: "center" }
                ]
              ]
            });
  
            // 工单明细
            var workInfoWorkOrderDetailTable = table.render({
              elem: "#workInfoWorkOrderDetailTable",
              data: workerInfoData.workOrderDetail,
              cellMinWidth: 120,
              cols: [
                [
                  { field: "deviceCode", title: "设备编码", align: "center" },
                  { field: "deviceModel", title: "设备型号", align: "center" },
                  {
                    field: "deviceYield",
                    title: "机台平均合格率",
                    align: "center"
                  },
                  {
                    field: "outputQuantity",
                    title: "排产数量",
                    align: "center"
                  },
                  {
                    field: "productionQuantity",
                    title: "计划生产数",
                    align: "center"
                  },
                  {
                    field: "prepositionTime",
                    title: "前置工单结束时间",
                    align: "center"
                  },
                  {
                    field: "workOrderQuantity",
                    title: "前置工单数",
                    align: "center"
                  },
                  {
                    field: "predictStartTime",
                    title: "预计开工时间",
                    align: "center"
                  },
                  {
                    field: "predictFinishTime",
                    title: "预计完工时间",
                    align: "center"
                  }
                ]
              ]
            });
  
            // 关联物料明细
            var workInfoMaterialDetailTable = table.render({
              elem: "#workInfoMaterialDetailTable",
              data: workerInfoData.materialDetail,
              cellMinWidth: 120,
              cols: [
                [
                  { type: "numbers", width: 50, title: "序号" },
                  {
                    field: "materialSkuCode",
                    title: "物料编号",
                    align: "center"
                  },
                  {
                    field: "materialSkuName",
                    title: "物料名称",
                    align: "center"
                  },
                  {
                    field: "materialSkuSpec",
                    title: "物料规格码",
                    align: "center"
                  },
                  { field: "unitName", title: "计量单位", align: "center" },
                  {
                    field: "fixationDosage",
                    title: "是否固定用量",
                    align: "center"
                  },
                  { field: "dosage", title: "用量", align: "center" }
                ]
              ]
            });
          }
        });
      }
  
      //排产记录
      function productionPlanRecordList(data) {
        console.info(data, 9999);
        admin.open({
          type: 1,
          area: ["82%", "80%"],
          title: "排产记录列表",
          content: $("#productionPlanRecordList").html(),
          success: function () {
            table.render({
              elem: "#productionRecordTable",
              url: config.base + "production/productionRecord/admin/productionRecord/list?productionPlanId=" + data.id,
              page: true,
              cellMinWidth: 100,
              cols: [
                [
                  { type: "numbers", title: "序号" },
                  {
                    field: "productionPlanRecordCode",
                    title: "制造令编号",
                    align: "center",
                    width: 160
                  },
                  {
                    field: "code",
                    title: "所属计划",
                    align: "center",
                    width: 160
                  },
                  {
                    field: "planTypeName",
                    title: "生产计划类型",
                    align: "center"
                  },
                  // { field: "orderTypeDesc", title: "计划订单类型", align: "center" },
                  {
                    field: "productTypeName",
                    title: "物料类别",
                    align: "center"
                  },
                  {
                    field: "customerSkuCode",
                    title: "物料编码",
                    align: "center"
                  },
                  {
                    field: "customerSkuSpec",
                    title: "物料规格",
                    align: "center"
                  },
                  {
                    field: "productionQuantity",
                    title: "计划生产数量",
                    align: "center"
                  },
                  // { field: "productionPlanHaveQuantity", title: "已排产数量", align: "center" },
                  {
                    field: "productionPlanQuantity",
                    title: "本次排产数量",
                    align: "center"
                  },
  
                  {
                    field: "shipmentTime",
                    title: "交货时间",
                    align: "center",
                    width: 160
                  },
                  { field: "statusDesc", title: "状态", align: "center" },
                  { field: "createTime", title: "创建时间", align: "center" },
                  {
                    align: "center",
                    toolbar: "#productionPlanRecordTableBar",
                    title: "操作",
                    fixed: "right"
                  }
                ]
              ],
              done: function (res, curr, count) {}
            });
  
            // 工具条点击事件
            table.on("tool(productionRecordTable)", function (obj) {
              var data = obj.data;
              if (obj.event === "checkPlan") {
                //详情
                // checkProductionPlanDetail(data);
                admin.formOpen({
                  area: ["85%", "90%"],
                  title: "生产计划排产",
                  path: "components/productionPlan/productionPieceRateForm.html",
                  success: function () {
                    parentData.eventName = "detail";
                    // parentData.id = data.id;
                    parentData.data = { ...data };
                    console.log(data, 9999);
                  }
                });
              }
            });
          }
        });
      }
  
      // 查询排产计划明细
      function checkProductionPlanDetail(data) {
        console.info(data, 9090);
        admin.open({
          type: 1,
          area: ["82%", "80%"],
          offset: ["65px"],
          title: "物料生产计划排产明细",
          content: $("#checkProductionPlanTemplate").html(),
          success: async function () {
            let productionPlanId = data.productionPlanId;
            let productionPlanRecordId = data.id;
            let customerSkuCode = data.customerSkuCode;
            // await admin.reqPro("enterprise/echnologyParam/admin/echnologyParam/list", {
            //   skuCode: customerSkuCode
            // });
            // 顶部详情数据
            var checkProductionPlanTable = table.render({
              elem: "#checkProductionPlanTable",
              data: [data],
              cellMinWidth: 100,
              cols: [
                [
                  { field: "code", align: "center", title: "计划编号" },
                  // { field: "orderTypeDesc", align: "center", title: "计划订单类型" },
                  {
                    field: "customerSkuCode",
                    align: "center",
                    title: "生产物料"
                  },
                  {
                    field: "customerSkuSpec",
                    align: "center",
                    title: "物料规格"
                  },
                  {
                    field: "productTypeName",
                    align: "center",
                    title: "所属物料系列"
                  },
                  {
                    field: "productionQuantity",
                    align: "center",
                    title: "计划生产数量"
                  },
                  {
                    field: "productionPlanQuantity",
                    title: "本次排产数量",
                    align: "center"
                  },
  
                  // { field: "customerName", align: "center", title: "客户信息" },
                  {
                    field: "shipmentTime",
                    align: "center",
                    title: "交货时间",
                    width: 160
                  },
                  { field: "statusDesc", align: "center", title: "状态" },
                  {
                    field: "createTime",
                    align: "center",
                    title: "创建时间",
                    width: 160
                  }
                ]
              ]
            });
            console.log(data, "234");
  
            // 查询计划的排产工序
            admin.req(
              // "enterprise/echnologyParam/admin/echnologyParam/list",
              "production/productionRecord/admin/productionRecord/detail",
              // "enterprise/echnologyParam/admin/echnologyParam/getEchonlogyInfoBy/" + data.bookId,
              {
                // skuCode: customerSkuCode
                type: data.planNature,
                productionPlanRecordId: data.id,
                processId: data.processId,
                bookId: data.bookId
              },
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  processList = res.data;
                  if (processList.length > 0) {
                    let checkProcessNodsData = [];
                    processList.forEach((item, index) => {
                      checkProcessNodsData.push({
                        title: item.name,
                        id: item.id
                      });
                    });
                    $("#checkProductionPlan").show();
                    // 渲染工序
                    laytpl(checkProcessNodsTitleTemplate.innerHTML).render(checkProcessNodsData, function (html) {
                      $("#checkProcessNodsTitle").html(html);
                      $("#checkProcessNodsTitle").find("li").removeClass("layui-this").eq(0).addClass("layui-this");
                    });
                    getProcessOutputAndYield(processList[0].id);
                    // getProcessDeviceByProcessId(processList[0].id);
                    table.reload("checkDeviceProductionTable", {
                      data: processList[0].productionProcessDevices
                    });
                    table.reload("checkRelevanceMaterialTable", {
                      data: processList[0].recordMaterialSkuVos
                    });
                  } else {
                    $("#checkProductionPlan").hide();
                  }
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "GET"
            );
  
            // 查询工序已排产数量和平均合格率
            function getProcessOutputAndYield(processId) {
              admin.req(
                "production/productionPlan/admin/productionPlan/getProcessOutputAndYield",
                {
                  productionPlanId: productionPlanId,
                  processId: processId
                },
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    $("input[name='checkRate']").val(res.data.yield + "%");
                    $("input[name='checkQuantity']").val(res.data.productionQuantity);
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                "GET"
              );
            }
  
            // 设备表格
            var checkDeviceProductionTable = table.render({
              elem: "#checkDeviceProductionTable",
              data: [],
              cellMinWidth: 120,
              cols: [
                [
                  { type: "numbers", width: 50, title: "序号" },
                  { field: "deviceModel", title: "设备型号", align: "center" },
                  { field: "deviceCode", title: "设备编码", align: "center" },
                  { field: "yeild", title: "机台平均合格率", align: "center" },
                  // { field: "planProductionQuantity", title: "计划排产数量", align: "center" },
                  {
                    field: "outputTime",
                    title: "当前计划截止时间",
                    align: "center"
                  }
                ]
              ]
            });
            // 关联物料表格
            var checkRelevanceMaterialTable = table.render({
              elem: "#checkRelevanceMaterialTable",
              data: [],
              cellMinWidth: 120,
              cols: [
                [
                  { type: "numbers", width: 50, title: "序号" },
                  { field: "skuCode", title: "物料编号", align: "center" },
                  { field: "skuName", title: "物料名称", align: "center" },
                  { field: "quantity", title: "需求数量", align: "center" }
                ]
              ]
            });
            // 查询计划排产明细工序的设备
            function getProcessDeviceByProcessId(processId) {
              admin.req(
                "production/productionPlan/admin/productionPlan/getProcessDeviceByProcessId",
                {
                  productionPlanId: productionPlanId,
                  productionPlanRecordId: productionPlanRecordId,
                  processId: processId
                },
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    console.log(res.data, 9999);
  
                    table.reload("checkDeviceProductionTable", {
                      data: res.data
                    });
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                "GET"
              );
            }
  
            // tab切换改变下标
            element.on("tab(checkProductionPlan)", function (v) {
              console.log(333333);
  
              let id = this.getAttribute("process-id");
  
              layer.load(2);
              getProcessOutputAndYield(id);
              // getProcessDeviceByProcessId(id);
              console.log(v, 9999);
  
              table.reload("checkDeviceProductionTable", {
                data: processList[v.index].productionProcessDevices
              });
              table.reload("checkRelevanceMaterialTable", {
                data: processList[v.index].recordMaterialSkuVos
              });
            });
          }
        });
      }
  
      // 数字转汉字
      function toChinesNum(num) {
        let changeNum = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
        let unit = ["", "十", "百", "千", "万"];
        num = parseInt(num);
        let getWan = (temp) => {
          let strArr = temp.toString().split("").reverse();
          let newNum = "";
          let newArr = [];
          strArr.forEach((item, index) => {
            newArr.unshift(item === "0" ? changeNum[item] : changeNum[item] + unit[index]);
          });
          let numArr = [];
          newArr.forEach((m, n) => {
            if (m !== "零") numArr.push(n);
          });
          if (newArr.length > 1) {
            newArr.forEach((m, n) => {
              if (newArr[newArr.length - 1] === "零") {
                if (n <= numArr[numArr.length - 1]) {
                  newNum += m;
                }
              } else {
                newNum += m;
              }
            });
          } else {
            newNum = newArr[0];
          }
  
          return newNum;
        };
        let overWan = Math.floor(num / 10000);
        let noWan = num % 10000;
        if (noWan.toString().length < 4) {
          noWan = "0" + noWan;
        }
        return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
      }
  
      // addProductionPlan
      
      
  
      // examineProductionPlan
      //审核生产计划
      function examineProductionPlanModel(data, _type) {
        admin.open({
          type: 1,
          area: ["1600px", "85%"],
          title: _type == "examine" ? "生产计划审核" : "生产计划详情",
          content: $("#examineProductionPlanForm").html(),
          success: function () {
            if (_type == "details") {
              $("#examineBox").hide();
              $('form[lay-filter="examineProductionPlanForm"] button[lay-filter="examineProductionPlanFormSubmit"]').hide();
            }
            let examineProductionPlanFormData = [];
            admin.reqSync(
              "production/productionPlan/admin/productionPlan/getProductionPlanInfoById",
              { id: data.id },
              (res) => {
                if (res.code === 200) {
                  examineProductionPlanFormData = res.data;
                }
              },
              "get"
            );
            examineProductionPlanFormData.auditPerson = config.getUser().username;
            if (examineProductionPlanFormData.planSource !== "order") {
              $("#orderCodeDiv").hide();
              $("#signOrNotDiv").hide();
              $("#contractDiv").hide();
            }
            form.val("examineProductionPlanForm", examineProductionPlanFormData.planData[0]);
            $("#accessoryImg").attr("src", examineProductionPlanFormData.planData[0].accessory);
            form.render("select");
  
            let examineProductionPlanTb = table.render({
              elem: "#examineProductionPlanTable",
              data: examineProductionPlanFormData.planData,
              page: false,
              cellMinWidth: 100,
              cols: [
                [
                  {
                    field: "code",
                    align: "center",
                    title: "计划编号",
                    width: 150
                  },
                  // { field: "categoryName", align: "center", title: "计划分类" },
                  { field: "typeName", align: "center", title: "计划类型" },
                  {
                    field: "planNatureDesc",
                    align: "center",
                    title: "计划性质"
                  },
                  { field: "demandQuantity", align: "center", title: "需求量" },
                  {
                    field: "surplusQuantity",
                    align: "center",
                    title: "剩余计划量"
                  },
                  {
                    field: "productionQuantity",
                    align: "center",
                    title: "本计划生产量"
                  },
                  {
                    field: "outputTime",
                    align: "center",
                    title: "计划产出时间",
                    width: 160
                  },
                  {
                    field: "creatorName",
                    align: "center",
                    title: "计划创建人",
                    width: 200,
                    templet: (d) => d.creatorName + "<br />电话：" + d.phone
                  },
                  {
                    field: "createTime",
                    align: "center",
                    title: "计划时间",
                    width: 160
                  }
                ]
              ]
            });
            let auditRecordsTb = table.render({
              elem: "#auditRecordsTable",
              data: examineProductionPlanFormData.auditData,
              page: false,
              cellMinWidth: 100,
              cols: [
                [
                  {
                    type: "numbers",
                    align: "center",
                    title: "序号",
                    width: 80
                  },
                  { field: "creatorName", align: "center", title: "审核人" },
                  {
                    field: "checkStatusDesc",
                    align: "center",
                    title: "审核结果"
                  },
                  { field: "remark", align: "center", title: "审核备注" },
                  { field: "createTime", align: "center", title: "审核时间" }
                ]
              ]
            });
  
            form.on("submit(examineProductionPlanFormSubmit)", function (d) {
              layer.load(2);
              d.field.id = data.id;
              admin.req(
                "production/productionPlan/admin/productionPlan/auditPlan",
                d.field,
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("productionPlanTable");
                    layer.closeAll("page");
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                "PUT"
              );
              return false;
            });
          }
        });
      }
  
      // 作废
      function toVoidToolCabinet(_data) {
        layer.confirm(
          "确定作废吗？",
          {
            skin: "layui-layer-admin"
          },
          function (i) {
            layer.close(i);
            layer.load(2);
            admin.req(
              "production/productionPlan/admin/productionPlan/cancellation",
              { id: _data.id },
              function (data) {
                layer.closeAll("loading");
                if (data.code == 200) {
                  layer.msg(data.msg, { icon: 1 });
                  table.reload("productionPlanTable");
                  layer.closeAll("page");
                } else {
                  layer.msg(data.msg, { icon: 2 });
                }
              },
              "PUT"
            );
          }
        );
      }
  
      //上传附件
      function uploadFile(_elem, pathId, inputId) {
        upload.render({
          elem: "#" + _elem,
          url: config.upload_url + "uploadFile",
          data: {},
          accept: "file",
          exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx|apk",
          headers: { Authorization: "Bearer " + config.getToken() },
          done: function (res) {
            if (res.code == 200) {
              layer.msg(res.msg || "上传成功", { icon: 1 });
              let imagUrl = res.data.url;
              $("#" + pathId).html("<a href='" + imagUrl + "' target='_blank'>" + imagUrl + "</a>");
              $("#" + inputId).val(imagUrl);
            } else if (res.code == 502) {
              return location.replace("admin/login.html");
            } else {
              layer.msg(res.msg || "上传失败", { icon: 2 });
            }
          }
        });
      }
  
      // 渲染下拉框数据
      function loadSelectHtml(data, tips, htmltarget, formName, type) {
        let html = " <option value>" + tips + "</option>";
        if (!data || data == null) {
          return;
        }
        for (let i = 0; i < data.length; i++) {
          if (type == 1) {
            html += `<option value='${data[i].id}'>${data[i].name}</option>`;
          } else if (type == 2) {
            html += `<option
                                    value='${data[i].skuCode}'
                                    productDetailId='${data[i].id}'
                                    skuName='${data[i].skuName}'
                                    skuSpec='${data[i].skuSpec}'
                                    productTypeId ='${data[i].productTypeId}'
                                    productTypeName ='${data[i].productTypeName}'
                                   >${data[i].skuCode}</option>`;
          } else if (type == 3) {
            html += `<option
                                    value='${data[i].id}'
                                    skuName='${data[i].customerSkuName}'
                                    skuSpec='${data[i].customerSpecCode}'
                                    residueQuantity='${data[i].residueQuantity}'
                                    quantity='${data[i].quantity}'
                                    orderProId='${data[i].id}'
                                    customerSkuItem = '${data[i].customerSkuItem}'
                                    productTypeId ='${data[i].proTypeId}'
                                    productTypeName ='${data[i].productTypeName}'
                                   >${data[i].customerSkuItem}</option>`;
          } else if (type == 4) {
            html += `<option
                                    value='${data[i].id}'
                                    deliveryTime='${data[i].deliveryTime}'
                                    orderRemark='${data[i].orderRemark}'
                                    orderCreatorName='${data[i].orderCreatorName}'
                                    signOrNot='${data[i].status}'
                                    signOrNotDesc='${data[i].statusDesc}'
                                    contractName='${data[i].contractName}'
                                    contractId='${data[i].contractId}'
                                    >${data[i].code}</option>`;
          } else if (type == 5) {
            html += `<option value='${data[i].id}'>${data[i].nodeNames}</option>`;
          } else {
            html += `<option value='${data[i].id}'>${data[i].name}</option>`;
          }
        }
        $("form[lay-filter='" + formName + "'] select[name='" + htmltarget + "']").html(html);
        form.render("select");
      }
    });
  </script>
  